using System.Collections;
using System.Collections.Specialized;
using Avalonia.Utilities;

namespace KinonekoSoftware.Studio.Utils
{
    public class CompositeCollection : AvaloniaObject, IEnumerable
    {
        public static readonly StyledProperty<IEnumerable> CollectionProperty;
        public static readonly StyledProperty<object>      BeforeProperty;
        public static readonly StyledProperty<object>      AfterProperty;

        static CompositeCollection()
        {
            CollectionProperty = AvaloniaProperty.Register<CompositeCollection, IEnumerable>(nameof(Collection));
            BeforeProperty     = AvaloniaProperty.Register<CompositeCollection, object>(nameof(Collection));
            AfterProperty      = AvaloniaProperty.Register<CompositeCollection, object>(nameof(Collection));
            
            CollectionProperty.Changed.Subscribe(args =>
            {
                var d = (CompositeCollection)args.Sender;

                if (args.GetNewValue<IEnumerable>() is INotifyCollectionChanged newNCC)
                {
                    newNCC.CollectionChanged += OnCollectionChanged;
                }
                
                if (args.GetOldValue<IEnumerable>() is INotifyCollectionChanged oldNCC)
                {
                    oldNCC.CollectionChanged -= OnCollectionChanged;
                }
                
            });
        }
        
        private static void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            throw new NotImplementedException();
        }
        
        public IEnumerator GetEnumerator()
        {
            throw new NotImplementedException();
        }

        public IEnumerable Collection
        {
            get => GetValue(CollectionProperty);
            set => SetValue(CollectionProperty, value);
        }
    }
}